#include "AnaDef.h"

TChain * InputFiles(const TString file, const TString tr, Char_t *dir=0x0)
{
  TChain *ch=new TChain(tr);

  if(file.Contains(".root"))
    ch->Add(file);
  else{
    ifstream fin(file);
    if(!fin){
      printf("XGLUtils::InputFiles file not found \n%s\n\n",file.Data()); exit(1);
    }

    TString buff;
    while(fin.good()){
      fin>>buff;
      if(buff!=""){
        if(dir){
          buff.Prepend(dir);
        }
        ch->Add(buff);
      }
    }
  }

  //const Int_t ent = ch->GetEntries(); //takes infinity time!!                                                                                                                                                            
  printf("\t%d trees!\n",ch->GetNtrees());

  return ch;
}

void ana0(const TString flist)
{
  TChain * ch = InputFiles(flist, "h1");
  //const Int_t ent = ch->GetEntries();
  //printf("tot entries %d\n", ent);
  ch->MakeClass("AnaSK");
}

int main(int argc, char* argv[])
{
  for(Int_t ii=0; ii<argc; ii++){
    printf("%d: %s\n", ii, argv[ii]);
  }

  ana0(argv[1]);

  return 0;
}
